<?php
require_once 'Zend/Test/PHPUnit/DatabaseTestCase.php';
/**
 *  test case.
 */
class LibraryModelTestCase extends Zend_Test_PHPUnit_DatabaseTestCase
{  
  /**
   * @var Zend_Application
   */
  protected $application;
  /**
   * @var Zend_Db_Adapter_Mysqli
   */
  protected $db;  
  /**
   * @var string
   */
  protected $dataset = 'files/gtuxbox_db.xml';
  /**
   * @var Zend_Test_PHPUnit_Db_Connection
   */
  protected $dbConn;

  /**
   * Prepares the environment before running a test.
   */
  protected function setUp ()
  {
    // instancio la aplicacion
    $this->application = new Zend_Application(
      APPLICATION_ENV,
      APPLICATION_PATH.'/configs/application.ini'
    );
    // autoloader
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->registerNamespace('Gtux_');
    // logger
    $writter    = new Zend_Log_Writer_Stream('php://output');
    $logger     = new Zend_Log($writter);
    Zend_Registry::set('logger', $logger);
    parent::setUp();
  }

  /**
   * Cleans up the environment after running a test.
   */
  protected function tearDown ()
  {
    $this->db->closeConnection();
    parent::tearDown();
  }
  
  /**
   * 
   * @return PHPUnit_Extensions_Database_DataSet_XmlDataSet
   */
  protected function getDataSet ()
  {
    return $this->createXMLDataSet($this->dataset);
  }

  /**
   * 
   * @return Zend_Test_PHPUnit_Db_Connection
   */
  protected function getConnection ()
  {
    $bootstrap = $this->application->getBootstrap();
    $pluginDb  = $bootstrap->getPluginResource('db');
    $this->db  = $pluginDb->init();
    $this->dbConn = $this->createZendDbConnection($this->db, 'gtuxbox_test');
    return $this->dbConn;
  }
  
  /**
   * Returns name of dataset file
   * @return string
   */
  protected function getDatasetFile() 
  {
  	return $this->dataset;
  }

}

?>